<template>
  <div>
    <van-datetime-picker
  v-model="currentDate"
  type="date"
  title="选择年月日"
  :min-date="minDate"
  :max-date="maxDate"
  @confirm="onConfirm"
  @cancel="$emit('close')"
/>
  </div>
</template>

<script>
import dayjs from 'dayjs'
import { editUserinfo } from '@/api/user'
export default {
  name: 'birthday',
  components: {},
  props: {
    value: {
      type: String,
      required: true
    }
  },
  data () {
    return {
      minDate: new Date(1970, 0, 1),
      maxDate: new Date(),
      currentDate: new Date(this.value)
    }
  },
  computed: {},
  watch: {},
  created () {

  },
  mounted () {

  },
  methods: {
    async onConfirm() {
      // 加载提示
      this.$toast.loading({
        message: '更新中...',
        forbidClick: true,
        // 设置转动时间，为0就无限转动
        duration: 0
      })
      try {
        await editUserinfo({ birthday: dayjs(this.currentDate).format('YYYY-MM-DD') })
        this.$emit('input', dayjs(this.currentDate).format('YYYY-MM-DD'))
        this.$toast.success('更新生日成功')
      } catch (err) {
        this.$toast.fail('更新生日失败')
      }
    }
  }
}
</script>

<style scoped lang="less">

</style>
